import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    //登录状态
    isLogin: false,
    //用户登录信息
    userinfo: {
      id: '',
      username: '',
      nickname:'',
      token:'',
      type:0
    },
  }),
  persist: {
    enabled: true,
    //需要缓存的数据
    strategies: [
      {
        key: "userinfo",
        paths: ["userinfo"],
        storage: sessionStorage
      },
      {
        key: "isLogin",
        paths: ["isLogin"],
        storage: sessionStorage
      }
    ],
  },
  getters: {

  },
  actions: {
    //退出登录
    logout() {
      this.isLogin = false
      this.userinfo = {
        id: 0,
        username: '',
        nickname:''
      }
    }
  }
})
